#!/bin/bash
# Usage: ./gen_lib.sh <dir>
# Description: generate cyberRT's UnderlayMessage lib to specific dir.

# 检查参数数量是否正确
if [ $# -ne 1 ]; then
  echo "用法: $0 <目标路径>"
  exit 1
fi

# 获取输入路径参数
target_dir="$1"

# 检查目标路径是否存在
if [ ! -d "$target_dir" ]; then
  echo "错误：目标路径 '$target_dir' 不存在"
  exit 1
fi

# 执行命令1
python3 ../main.py ./underlaymessage/dal

# 拷贝3个文件到目标路径
cp ../build/dal/build/libdal__dalidl_typesupport_cpp.so "$target_dir"
cp ../build/dal/build/libdal__dalidl_typesupport_fastrtps_cpp.so "$target_dir"
cp ../build/dal/build/libdal__dalidl_typesupport_introspection_cpp.so "$target_dir"

# 删除 ../build/dal 目录
rm -r ../build/dal

# 执行命令2
python3 ../main.py ./underlaymessage_compatible/dal

# 拷贝文件并重命名
cp ../build/dal/build/libdal__dalidl_typesupport_fastrtps_cpp.so "$target_dir/libdal__dalidl_typesupport_fastrtps_cpp_compatible.so"
cp ../build/dal/build/libdal__dalidl_typesupport_introspection_cpp.so "$target_dir/libdal__dalidl_typesupport_introspection_cpp_compatible.so"

# 删除 ../build/dal 目录
rm -r ../build/dal

echo "gen_lib.sh 操作完成"